home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4597 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: qsort with large files
  5. Date: 5 Feb 1996 19:33:51 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4f5m2v$8at@gail.ripco.com>
  8. NNTP-Posting-Host: golden.ripco.com
  9.  
  10. Claude Leyo <leyo@mail.atlantic-line.fr>
  11. in <3113080C.349E@mail.atlantic-line.fr> asks:
  12.  
  13. >I don't succeed trying to sort a large array of names in a structure
  14. >when the array is >64K. Is there a limitation of qsort() ? Thanks for
  15. >help.
  16.  
  17. Some side issues:
  18. 1)
  19. Your function
  20.  
  21. >int sort_function( name_list huge *p1, name_list huge *p2)
  22. >{ return strcmp((( struct name_list *)p1)->name,
  23. >                (( struct name_list *)p2)->name);
  24. >}
  25.  
  26. is used as the comparison function in the call to qsort.  The comparison
  27. function takes two arguments of type "const void *".  There is no reason
  28. to suppose sort_function will perform as you expect.  Try something like:
  29.  
  30. #define huge    /* necessary for my compiler - ignore */
  31. int sort_function(const void *v1, const void *v2)
  32. {
  33.     const struct name_list huge *p1 = v1, *p2 = v2;
  34.     return strcmp(p1->name, p2->name);
  35. }
  36.  
  37. I hope the syntax of the non-C non-keyword `huge' corresponds to your
  38. implementation.
  39.  
  40. 2) Since your program uses `struct name_list' and `name_list' as
  41.     synonyms without a typedef, this is C++ code, not C code.  If you
  42.     want it to be "Safe C", always uses `struct name_list'.  If it is
  43.     meant to be C and not C++, a typedef will make the synonmy ok.
  44.  
  45. 3) Since your code uses "//" EOL comments, it is C++ code, not C code.
  46.     When you post to comp.lang.c, "//" comments are syntax errors.  Use
  47.     "/* ... */" comments here.
  48.  
  49. /***********/
  50. Now to the question you ask...
  51.  
  52. Since your program uses huge declarations and farcalloc() calls, it is
  53. probably written for a MSDOS compiler.  Limitations of 64K on objects
  54. are a problem of your implementation.  There is some discussion in the
  55. FAQ, but better to read your implementation documentation.  Even better,
  56. use a 32-bit flat-memory model compiler.
  57.                       
  58. --
  59. * Martin Ambuhl       net: mambuhl@ripco.com
  60. * Chicago, IL (USA)    
  61.